package com.oauth.facebook.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.oauth.facebook.client.beans.FacebookUser;

public class ConnectionPanel extends Composite {

	private static ConnectionPanelUiBinder uiBinder = GWT.create(ConnectionPanelUiBinder.class);

	interface ConnectionPanelUiBinder extends UiBinder<HorizontalPanel, ConnectionPanel> {
	}

	@UiField
	HorizontalPanel hPanel1;

	@UiField
	HTMLPanel hPanel2AlignLeft;

	@UiField
	Image profileImage;

	@UiField
	Label name;

	@UiField
	Label position;

	@UiField
	Label status;

	FacebookUser mUser;

	public ConnectionPanel() {
		initWidget(uiBinder.createAndBindUi(this));
		hPanel1.setCellHorizontalAlignment(hPanel2AlignLeft, VerticalPanel.ALIGN_LEFT);
	}

	public ConnectionPanel(FacebookUser user) {
		mUser = user;
		initWidget(uiBinder.createAndBindUi(this));
		init();
		hPanel1.setCellHorizontalAlignment(hPanel2AlignLeft, VerticalPanel.ALIGN_LEFT);
	}

	public void setUser(FacebookUser user) {
		mUser = user;
		init();
	}

	public void init() {
		profileImage.setUrl("https://graph.facebook.com/" + mUser.getId() + "/picture");
		status.setText(mUser.getStatus());
		name.setText(mUser.getName());
	}

	public void setSpacing(int spacing) {
		hPanel1.setSpacing(spacing);
	}

	public void setWidth(String width) {
		hPanel1.setWidth(width);
	}

}
